<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/common.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script type="text/javascript" src="./js/abkj/auth/api/account.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/userinfo.js"></script>
	<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
	<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
	<span class="layui-breadcrumb">
			<a href="">首页</a>
			<a><cite>用户管理</cite></a>
			<a><cite>参赛选手</cite></a>
	</span>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
		<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
	</a>
</div>
<div class="layui-fluid">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card">
				<div class="layui-card-body ">
					<form class="layui-form layui-col-space5 flex" style="display: flex;" @submit.prevent>
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5" style="width: 40px;">账号</div>
							<input type="text" name="accountValue" placeholder="账号" autocomplete="off" class="layui-input"></div>
						<div class="layui-input-inline layui-show-xs-block">
							<button class="layui-btn" lay-submit="" lay-filter="search">
								<i class="layui-icon">&#xe615;</i></button>
						</div>
					</form>
				</div>
				<div class="layui-card-body" id="content" v-cloak>
					<table class="layui-table layui-form" id="table" lay-filter="table">
						<span>共计{{ total }}条数据</span>
					</table>
					<section id="page"></section>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script type="text/html" id="operating">
	<a href="javascript:;" class="layui-table-link" onclick=app.stop('{{JSON.stringify(d)}}')>{{ d.status === 1 ? '启动' : '禁用' }}</a>
</script>
<script type="text/javascript" src="./js/abkj/auth/api/userinfoview.js"></script>
<script src="./js/vue.js"></script>
<script src="./js/jquery.min.js"></script>
<script>
	var app=new Vue({
		el: '#content',
		data: {
			listAccount:[],
			listUserInfo:[],
			list:[],
			total: 0,
			pageNo: 1,
			pageSize: 50,
			status:['审核','待审核' ,'通过', '不通过'],
			participate:['审核','参赛' ,'弃权' ],
			cols: [ //表头
				{field: 'index', title: '序号', width: 80},
				{field: 'account', title: '账号', width: 110},
				{field: 'nickName', title: '昵称', width: 110},
				{field: 'name', title: '姓名', width: 110},
				{field: 'gradeName', title: '年级', width: 110},
				{field: 'idcard', title: '证件号', width: 110},
				{field: 'gender', title: '性别', width: 110},
				{field: 'email', title: '电子邮箱', width: 135},
				{field: 'createTime', title: '注册时间', width: 110},
				{field: 'operating', title: '操作', width: 135, templet: '#operating'},
			]
		},
		mounted: function () {
			this.getData()
			var vm=this;
			layui.use('form',function(){
				layui.form.on('submit(search)', function (data) {
						vm.getData()
						app.queryByAccount(data.field.accountValue)
						// layer.msg(JSON.stringify(data.field), function () {
						// location.href = 'index.html'
						// })
						return false
					})
			})
		},
		methods:{
			opentab:function(name,url){
				//单击事件
				console.log(name)
				console.log(url)
				xadmin.add_tab(name,url)
			},
			setAccountState:function(varId,state){
				//state 0 启用 1 禁用
				var obj={
					id:varId,
					isProhibit:state
				}
				AccountupdateById(obj,function(data){
					//修改成功
				},function(status,message){
					//修改失败
				})
			},
			getAccountFromMem:function(varId){
				for(var i=0;i<this.listAccount.length;++i){
					if(this.listAccount[i].id==varId){
						return this.listAccount[i];
					}
				}
			},
			queryByAccount:function(varAccount){
				var vm = this
				//帐号查询
				var queryData = {
				    page:{
				        current:vm.pageNo, //当前页数
				        size: vm.pageSize   //每页长度
				    },
				    cond:{ //条件
				        eq:{ // 多条件对象
				        	userName:varAccount,
				        	roleId:2
	                    }
				    }
				};
				this.loadAccount(queryData)
			},
			loadAccount:function(varParam){
				var vm = this
				UserinfoViewPageList(varParam,function(data){
						vm.listUserInfo=data;
						vm.total = data.total
						vm.list = []
						for(var i=0; i < vm.listUserInfo.records.length; ++i){
							vm.listUserInfo.records[i].index=i+(vm.listUserInfo.current-1)*vm.listUserInfo.size;
							// var varAccount = vm.listUserInfo.records[i].userName;
							vm.listUserInfo.records[i].account=vm.listUserInfo.records[i].userName;
							// vm.listUserInfo.records[i].createTime=varAccount.createTime;
							vm.listUserInfo.records[i].status= vm.listUserInfo.records[i].isProhibit
							vm.list.push(vm.listUserInfo.records[i])
						}
						vm.init()
						// var ids=[];
						// for(var i=0; i<data.records.length;++i){
						// 	ids.push(data.records[i].id);
						// }
						// var userInfoParam={
						// 	in:{
						// 		data:ids,
						// 		attrName:"id"
						// 	}
						// }
						// AccountqueryList(userInfoParam,function(data){
						// 	vm.listAccount=data;
						// 	vm.list = []
						// 	for(var i=0; i < vm.listUserInfo.records.length; ++i){
						// 		vm.listUserInfo.records[i].index=i+(vm.listUserInfo.current-1)*vm.listUserInfo.size;
						// 		var varAccount = vm.getAccountFromMem(vm.listUserInfo.records[i].id);
						// 		vm.listUserInfo.records[i].account=varAccount.userName;
						// 		vm.listUserInfo.records[i].createTime=varAccount.createTime;
						// 		vm.listUserInfo.records[i].status= varAccount.isProhibit
						// 		vm.list.push(vm.listUserInfo.records[i])
						// 	}
						// 	vm.init()
						// },function(status,message){

						// })

					},function(status,message){

				})
				// AccountPageList(varParam,function(data){
				// 	app.listAccount=data;
				// 	var ids=[];
				// 	for(var i=0; i<data.records.length;++i){
				// 		ids.push(data.records[i].id);
				// 	}
				// 	var userInfoParam={
				// 		in:{
				// 			data:ids,
				// 			attrName:"id"
				// 		}
				// 	}
				// 	UserInfoqueryList(userInfoParam,function(data){
				// 		app.listUserInfo=data;
				// 		for(var i=0; i < data.length; ++i){
				// 			data[i].index=i+(app.listAccount.current-1)*app.listAccount.size;
				// 			var varAccount = app.getAccountFromMem(data[i].id);
				// 			data[i].account=varAccount.userName;
				// 			data[i].createTime=varAccount.createTime;
				// 			data[i].status= varAccount.isProhibit
				// 			app.list.push(data[i])
				// 		}
				// 	},function(status,message){

				// 	})
				// },function(status,message){

				// })

			},

			stop: function (data) {
				data = JSON.parse(data)
				console.log(data)
				var text = data.status === 1 ? '启用' : '禁用'
				// 禁用启用逻辑
				var reqObj={
					id:data.id,
					isProhibit:data.status === 1?0:1
				}
				layer.confirm('确定' + text + '吗？', function () {
					// 掉接口
					AccountupdateById(reqObj,function(data){
						layer.msg(text + '成功!', {icon: 1})
						location.reload()
					})
				})
			},
			getData(){
				var vm = this
				var queryData = {
				    page:{
				        current: vm.pageNo, //当前页数
				        size: vm.pageSize   //每页长度
				    },
				    cond:{ //条件
				        eq:{ // 多条件对象
				        	roleId:2
	                    }
				    }
				};
				this.loadAccount(queryData);
			},
			init:function() {
				var that = this
				var vm = this
				layui.use(['form', 'laypage','table'], function () {
					// var laypage = layui.laypage;
					// //执行一个laypage实例
					// laypage.render({
					// 	elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
					// 	,count: 16 //数据总数，从服务端得到
					// });
					var table = layui.table
					var form = layui.form
					//头工具栏事件
					table.render({
						elem: '#table',
						url:'',
						title: '用户数据表',
						cols: [that.cols],
						data: that.list,
						count:app.listAccount.total
					})
					layui.laypage.render({
						elem: 'page',
						count: vm.total,
						current: vm.pageNo,
						limit: vm.pageSize,
						jump: function (obj, first) {
							if (first) return
							vm.pageNo = obj.curr
							vm.getData()
						}
					})
					// form.on('submit(search)', function (data) {
					// 	// vm.getData()
					// 	// app.queryByAccount(data.field.accountValue)
					// 	// layer.msg(JSON.stringify(data.field), function () {
					// 	// location.href = 'index.html'
					// 	// })
					// 	return false
					// })
				})
			}
		}
	})
</script>

</html>
